<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <!--引入Vue-->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <div class="root">
      <h2>今天天气很{{info}}</h2>
      <button @click="changeWeather">切换天气</button>
    </div>
</body>

<script type="text/javascript">
  let vue = new Vue({
    el: '.root',
    data: {
      isHot: true,
    },
    /**
     * 监视属性变化
     */
    watch:{
      isHot: function(newValue,oldValue) {
        console.log('isHot被修改了,'+newValue+','+oldValue)
      }
      /**
       * 完整
       */
      // isHot: {
      //   /**
      //    * handler
      //    * 当isHot属性值发生改变时,handler方法会被调用
      //    */
      //   handler(newValue,oldValue){
      //     //在这里就能得到变化前的值和变化后的值
      //     console.log('isHot被修改了,'+newValue+','+oldValue)
      //   },
      // },
    },
    computed:{
      info(){
        return this.isHot ? '炎热' : '凉爽'
      }
    },
    methods:{
      changeWeather(){
        this.isHot = !this.isHot
      }
    }
  })
</script>
</html>
